package com.wyq.miaosha.rabbitmq;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;


@Configuration
public class MQConfig {

    public static final String QUEUE = "queue";
    public static final String TOPIC_QUEUE1 = "topic.queue1";
    public static final String TOPIC_QUEUE2 = "topic.queue2";
    public static final String TOPIC_EXCHANGE = "topic.exchange";
    public static final String ROUTING_KEY1 = "topic.key1";
    public static final String ROUTING_KEY2 = "topic.#";
    public static final String FANOUT_QUEUE = "fanout.queue";
    public static final String FANOUT_EXCHANGE = "fanout.exchange";
    public static final String HEADERS_QUEUE = "headers.queue";
    public static final String HEADERS_EXCHANGE = "headers.exchange";
    public static final String MIAOSHA_QUEUE = "miaosha.queue";

    @Bean
    public Queue MiaoshaQueue(){
        return new Queue(MIAOSHA_QUEUE,true);
    }
//    /**
//     * Direct模式 交换机Exchange
//     * @return
//     */
//    @Bean
//    public Queue queue(){
//        return new Queue(QUEUE,true);
//    }
//
//    /**
//     * Topic模式 交换机Exchange
//     */
//    @Bean
//    public Queue topicQeue1(){
//        return new Queue(TOPIC_QUEUE1,true);
//    }
//    @Bean
//    public Queue topicQeue2(){
//        return new Queue(TOPIC_QUEUE2,true);
//    }
//    @Bean
//    public TopicExchange topicExchange(){
//        return new TopicExchange(TOPIC_EXCHANGE);
//    }
//    @Bean
//    public Binding topicBinding1(){
//        return BindingBuilder.bind(topicQeue1()).to(topicExchange()).with(ROUTING_KEY1);
//    }
//    @Bean
//    public Binding topicBinding2(){
//        return BindingBuilder.bind(topicQeue2()).to(topicExchange()).with(ROUTING_KEY2);
//    }
//
//    /**
//     * Fanout模式 交换机EXCHANGE
//     */
//    @Bean
//    public FanoutExchange fanoutExchange(){
//        return new FanoutExchange(FANOUT_EXCHANGE);
//    }
//    @Bean
//    public Binding fanoutBinding1(){
//        return BindingBuilder.bind(topicQeue1()).to(fanoutExchange());
//    }
//    @Bean
//    public Binding fanoutBinding2(){
//        return BindingBuilder.bind(topicQeue2()).to(fanoutExchange());
//    }
//
//    /**
//     * Headers模式 交换机EXCHANGE
//     */
//    @Bean
//    public HeadersExchange headersExchange(){
//        return new HeadersExchange(HEADERS_EXCHANGE);
//    }
//    @Bean
//    public Queue headerQueue(){
//        return new Queue(HEADERS_QUEUE,true);
//    }
//    @Bean
//    public Binding headersBinding(){
//        Map<String,Object> map = new HashMap<String,Object>();
//        map.put("headers1","value1");
//        map.put("headers2","value2");
//        return BindingBuilder.bind(headerQueue()).to(headersExchange()).whereAll(map).match();
//    }

}
